/**
 * Copyright (c) 2019 EOVA.CN. All rights reserved.
 * 
 * Licensed under the EPPL license: http://eova.cn/eppl.txt
 * For authorization, please contact: admin@eova.cn
 */
package com.oss.model;

import com.eova.common.base.BaseModel;
import com.eova.common.utils.xx;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

import java.util.List;

/**
 * 收货地址
 * @author Jieven
 *
 */
public class Area extends BaseModel<Area> {

	private static final long serialVersionUID = 1064291771401662738L;

	public static final Area dao = new Area();

	public List<Area> getPro(){
		String sql = "select * from base_area where pid = ? ";
		return this.find(sql,1);
	}

	public List<Area> getName(String name,int lv){
		String sql = "select * from base_area where pid = (select id from base_area where name=? and lv=?) ";
		return this.find(sql,name,lv);
	}

	public List<Record> getName(int pid, int lv){
		String sql = "select id ID,name CN from base_area where pid = ? and lv = ?";
		return Db.use(xx.DS_MAIN).find(sql, new Object[]{pid,lv});
	}

	public Area getName(String name){
		String sql = "select * from base_area where name like ? and lv=1 ";
		return this.findFirst(sql,name+"%");
	}

	public String getNameById(String id){
		String sql = "select * from base_area where id = ?";
		Area area = this.findFirst(sql,new Object[]{id});
		return xx.isEmpty(area)?"":area.getStr("name");
	}

}